<?php
/**
 * Created by PhpStorm.
 * User: iraklis
 * Date: 1/5/14
 * Time: 4:19 PM
 */
session_start();
if (!isset($_SESSION["level"])) header("location:login.php");
include 'config.php';
include 'db_connection.php';

$userID = $_SESSION['u_id'];
$GET_userID = $_GET['u_id'];
if ($userID == $GET_userID) {
    $query = mysql_query("SELECT * FROM REMINDERS WHERE u_id = \"$userID\"");
    if (!$query) {
        die('Invalid SELECT query: ' . mysql_error());
    }
    $count = mysql_num_rows($query);
    $i = 1;

    echo '{"total_rows":' . $count . ',"content":[';
    while ($rows = mysql_fetch_row($query)) {
        //printf("Title: %s, Start Date: %s,Start time: %d, Location: %s,Description: %s, Repeatition: %s, ",$rows[2], $rows[3],$rows[4], $rows[7],$rows[8], $rows[9],$rows[10]);
        //print_r($rows);
        //echo json_encode($rows);
        //$rows = mysql_fetch_row($query);
        //echo '{"id":'. $rows[1] .',"title":"'. "$rows[2]" . '", start":"' . "$rows[3]" . '","start_time":"' . "$rows[4]" . '","end":"'. "$rows[5]" .'","end_time":"' . "$rows[6]" . '","location":"' . "$rows[7]" . '","description":"' . "$rows[8]" . '","repeatition":"' . "$rows[9]" . '","remind_type":"' . "$rows[10]" . '"}';
        $repeatition = $rows[9];
        if ($repeatition == "daily") {}
        else if ($repeatition == "weekly") {}
        else if ($repeatition == "monthly") {}
        else if ($repeatition == "yearly") {}
        else if ($repeatition == "once") {}
        if ($i++ < $count) {
            echo '{"id":'. $rows[0] . ',"title":"' . $rows[2] . '", "start":"' . "$rows[3]" . '","start_time":"'. $rows[4] . '","end":"'. "$rows[5]" . '","end_time":"' . $rows[6] . '","allDay":false' . '},';
        } // end of if

        else {
            echo '{"id":'. $rows[0] . ',"title":"' . $rows[2] . '", "start":"' . "$rows[3]" . '","start_time":"'. $rows[4] . '","end":"'. "$rows[5]" . '","end_time":"' . $rows[6] . '","allDay":false' . '}';
        }// end of else
    }// end of while
    echo ']}';
}